﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using EHSubmit.Model;
using EHSubmit.Util;

namespace EHSubmit.Logic
{

    /// <summary>
    ///InstituteManager 的摘要说明
    /// </summary>
    public class InstituteManager
    {
        private const string SQL_SELECT_Institute = "SELECT InstituteID,InstituteName FROM Institute";
        public InstituteManager(){}

        /// <summary>
        /// 查询学院信息
        /// </summary>
        /// <returns>学院信息</returns>
        public IList<Institute> GetInstitutes()
        {
            IList<Institute> instituteList= new List<Institute>();

            using(SqlDataReader rdrInstitutes = (SqlDataReader)SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_Institute))
            {
                while(rdrInstitutes.Read())
                {
                    Institute institute = new Institute();
                    institute.InstituteID = rdrInstitutes["InstituteID"] is DBNull ? -1 : (int)rdrInstitutes["InstituteID"];                        //学院ID 标识属性
                    institute.InstituteName = rdrInstitutes["InstituteName"] is DBNull ? string.Empty : (string)rdrInstitutes["InstituteName"];     //学院名称
                    
                    instituteList.Add(institute);
                }
            }

            return instituteList;
        }
    }
}